﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MVCAppToolkit.UserTests
{
    [TestClass]
    public class SearchFormToolkitPackagingSpec : VsixPackagingTest
    {
        private const string DeployedContentDirectory = "UserTests.Content";
        private const string DeployedVsixItem = DeployedContentDirectory + @"\SearchFormToolkit.11.0.vsix";

        [TestClass]
        [DeploymentItem(DeployedContentDirectory, DeployedContentDirectory)]
        public class GivenTheCompiledVsix : VsixPackagingTest.GivenAVsix
        {
            /// <summary>
            /// Returns the relative path to the deployed Vsix file in the project
            /// </summary>
            protected override string DeployedVsixItemPath
            {
                get
                {
                    return DeployedVsixItem;
                }
            }
         
            [TestMethod, TestCategory("Integration")]
            public void ThenVsixInfoCorrect()
            {
                //Identifier, Name, Author, Version
                Assert.AreEqual(@"4f37df5a-37a9-4d0c-a430-7e4eecd342a0", this.VsixInfo.Header.Identifier);
                Assert.AreEqual(@"MVC Search Form Toolkit", this.VsixInfo.Header.Name);
                Assert.AreEqual(@"A pattern toolkit for creating search form views for MVC applications.", this.VsixInfo.Header.Description);
                Assert.AreEqual(@"NuPattern", this.VsixInfo.Header.Author);
                Assert.AreEqual("1.3.20.0", this.VsixInfo.Header.Version.ToString());
                
                //License, Icon, PreviewImage, MoreInfoUrl, GettingStartedGuide
                //Assert.AreEqual(@"LICENSE.txt", this.VsixInfo.Header.License);
                Assert.AreEqual(@"Resources\ToolkitIcon.png", this.VsixInfo.Header.Icon);
                Assert.AreEqual(@"", this.VsixInfo.Header.PreviewImage);
                Assert.AreEqual(null, this.VsixInfo.Header.MoreInfoUrl);
                Assert.AreEqual(null, this.VsixInfo.Header.GettingStartedGuide);

#if VSVER10
                Assert.AreEqual(@"4.0", this.VsixInfo.Header.SupportedFrameworkMinVersion.ToString());
                Assert.AreEqual(@"4.0", this.VsixInfo.Header.SupportedFrameworkMaxVersion.ToString());
#endif
#if VSVER11
                Assert.AreEqual(@"4.0", this.VsixInfo.Header.SupportedFrameworkVersionRange.Minimum.ToString());
                Assert.AreEqual(@"4.5", this.VsixInfo.Header.SupportedFrameworkVersionRange.Maximum.ToString());
#endif
                //SupportedProducts
#if VSVER10
                Assert.AreEqual(1, this.VsixInfo.Header.SupportedVSVersions.Count(t => t.Major.ToString() + "." + t.Minor.ToString() == "10.0"));
#endif
#if VSVER11
                Assert.AreEqual(1, this.VsixInfo.Targets.Count(t => t.VersionRange.Minimum.ToString() == "11.0"));
#endif
            }

            [TestMethod, TestCategory("Integration")]
            public void ThenContainsGuidance()
            {
                //Guidance (\\GeneratedCode\Gudiance\Content\*
                Assert.IsTrue(this.FolderNotEmpty(@"GeneratedCode\Guidance\Content", "*.mht"));
            }
                
            [TestMethod, TestCategory("Integration")]
            public void ThenContainsAssets()
            {
                //Templates (\\Assets\Templates\*
                //Assert.IsTrue(this.FolderContainsExclusive(@"Assets\Templates\Projects",
                //    new[]
                //        {
                //        }));

                //Assert.IsTrue(this.FolderContainsExclusive(@"Assets\Templates\Items",
                //    new[]
                //        {
                //        }));

                Assert.IsTrue(this.FolderContainsExclusive(@"Assets\Templates\Text",
                    new[]
                        {
                            "Actions.t4",
                            "QueryForm.gen.t4",
                            "QueryModel.t4",
                            "ResultsForm.gen.t4",
                            "SearchProvider.t4",
                        }));
            }

            [TestMethod, TestCategory("Integration")]
            public void ThenContainsResources()
            {
                //Schema files (\Resources\*)
                Assert.IsTrue(this.FolderContainsExclusive(@"Resources",
                    new[]
                        {
                            "ToolkitIcon.png",
                        }));
            }

            [TestMethod, TestCategory("Integration")]
            public void ThenContainsRedistributables()
            {
                //Redist files
                Assert.IsTrue(this.FolderContainsExclusive("",
                    new[]
                        {
                            "extension.vsixmanifest",
                            //"[Content_Types].xml",
                            //"LICENSE.txt",

                            // Assemblies
                            "SearchFormToolkit.dll",
                            "SearchFormToolkit.Automation.dll",
                        }));
            }
        }
    }
}
